/*
 * 描          述:  <描述>
 * 修  改   人:  PengQingyang
 * 修改时间:  2022年5月2日
 * <修改描述:>
 */
package com.tx.core.method.databinder.impl;

import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.lang.Nullable;
import org.springframework.validation.DataBinder;

import com.tx.core.method.databinder.NativeBindingInitializer;

/**
 * 默认本地的NativeBindingInitializer的实现<br/>
 * <功能详细描述>
 * 
 * @author  PengQingyang
 * @version  [版本号, 2022年5月2日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class DefaultNativeBindingInitializer
        implements NativeBindingInitializer {
    
    private boolean autoGrowNestedPaths = true;
    
    private boolean directFieldAccess = false;
    
    @Nullable
    private PropertyEditorRegistrar[] propertyEditorRegistrars;
    
    /**
     * @param binder
     */
    @Override
    public void initBinder(DataBinder binder) {
        binder.setAutoGrowNestedPaths(this.autoGrowNestedPaths);
        if (this.directFieldAccess) {
            binder.initDirectFieldAccess();
        }
        if (this.propertyEditorRegistrars != null) {
            for (PropertyEditorRegistrar propertyEditorRegistrar : this.propertyEditorRegistrars) {
                propertyEditorRegistrar.registerCustomEditors(binder);
            }
        }
    }
    
    /**
     * @return 返回 autoGrowNestedPaths
     */
    public boolean isAutoGrowNestedPaths() {
        return autoGrowNestedPaths;
    }
    
    /**
     * @param 对autoGrowNestedPaths进行赋值
     */
    public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths) {
        this.autoGrowNestedPaths = autoGrowNestedPaths;
    }
    
    /**
     * @return 返回 directFieldAccess
     */
    public boolean isDirectFieldAccess() {
        return directFieldAccess;
    }
    
    /**
     * @param 对directFieldAccess进行赋值
     */
    public void setDirectFieldAccess(boolean directFieldAccess) {
        this.directFieldAccess = directFieldAccess;
    }
    
    /**
     * @return 返回 propertyEditorRegistrars
     */
    public PropertyEditorRegistrar[] getPropertyEditorRegistrars() {
        return propertyEditorRegistrars;
    }
    
    /**
     * @param 对propertyEditorRegistrars进行赋值
     */
    public void setPropertyEditorRegistrars(
            PropertyEditorRegistrar[] propertyEditorRegistrars) {
        this.propertyEditorRegistrars = propertyEditorRegistrars;
    }
}
